package com.example.customizedgroupmessage;

public class Template {

	private String name;
	private String status;
	private String organization;
	private String custom;
	private String _id; //date
	private String originalMsg;
	private String title;
	public String[] analyzedMsg;
	public boolean isCustom;

	public Template() {
		this.name = "";
		this.status = "";
		this.organization = "";
		this.custom = "";
		this.originalMsg = null;
		this.analyzedMsg = new String[] {};
		isCustom = false;
	}

	public void analyzeMsg() {
		/* delimiter */
		String delimiter = "/#";
		/* given string will be split by the argument delimiter provided. */
		analyzedMsg = originalMsg.split(delimiter);
		/* print substrings */
		//for(int i =0; i < analyzedMsg.length ; i++)
			//System.out.println(analyzedMsg[i]);
		/* check custom */
		for(int i =0; i < analyzedMsg.length ; i++){
			if(analyzedMsg[i].equals("#custom")){
				isCustom = true;
			}
		}
	}
	
	public void setName(String _name) {
		name = _name;
	}
	
	public void setStatus(String _status) {
		status = _status;
	}
	
	public void setOrganization(String _organization) {
		organization = _organization;
	}
	
	public void setCustom(String _custom) {
		custom = _custom;
	}
	
	public void setId(String __id) {
		_id = __id;
	}
	
	public void setOriginalMsg(String _originalMsg) {
		originalMsg = _originalMsg;
	}
	
	public void setTitle(String _title) {
		title = _title;
	}
	
	public String getId() {
		return _id;
	}
	
	public String getTitle() {
		return title;
	}

	public String getOriginalMsg() {
		return originalMsg;
	}
	
	public String[] getAnalyzedMsg() {
		return analyzedMsg;
	}
	
	public String translate(){
		StringBuffer strBuf = new StringBuffer();
		
		for(int i =0; i < analyzedMsg.length ; i++){
			if(analyzedMsg[i].equals("#name")){
				strBuf.append(name);
			}
			else if(analyzedMsg[i].equals("#status")){
				strBuf.append(status);
			}
			else if(analyzedMsg[i].equals("#org")){
				strBuf.append(organization);
			}
			else if(analyzedMsg[i].equals("#custom")){
				strBuf.append(custom);
			}
			else{
				strBuf.append(analyzedMsg[i]);
			}
		}
		
		return strBuf.toString();
	}

}
